package com.bitmain.mmst.miner.statistic.helper;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.bitmain.mmst.common.util.SpringContextHolder;
import com.bitmain.mmst.domain.MineHashrateOverview;
import com.bitmain.mmst.domain.MinerDetectDetail;
import com.bitmain.mmst.domain.ShelfHashrateOverview;
import com.bitmain.mmst.web.dao.StatisticDao;

/**
 * 
 *
 * @author Richard - rui.wu@bitmain.com
 * @since 2016年8月9日 
 *
 */
public class OverviewDataHelper {
	private static StatisticDao statisticDao = SpringContextHolder.getBean("statisticDao", StatisticDao.class);
	
	public static List<MinerDetectDetail> getDetectDetails(long minerShelfId, long detectTime) {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("minerShelfId", minerShelfId);
		params.put("detectTime", detectTime);
		return statisticDao.selectDetectDetails(params);
	}

	public static void saveShelfHashrateOverview(ShelfHashrateOverview shelfOverview) {
		statisticDao.insertShelfHashrateOverview(shelfOverview);
	}

	public static boolean shelfHashrateOverviewTableExists(int year) {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("year", year);
		return statisticDao.countShelfHashrateOverviewTable(params) >0;
	}

	public static void createShelfHashrateOverviewTable(int year, long yearBeginning, long yearEnd) {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("year", year);
		params.put("yearBeginning", yearBeginning);
		params.put("yearEnd", yearEnd);
		statisticDao.createShelfHashrateOverviewTable(params);
	}

	public static void saveMineHashrateOverview(MineHashrateOverview mineOverview) {
		statisticDao.insertMineHashrateOverview(mineOverview);
	}
}
